
import { getUserHealth } from "@/api/api";
import { userData } from "@/store/userData";
import { bodyData } from "@/store/bodyData";


export const getBodyData = async ()=>{
    const USER_DATA = userData();
    const BODY_DATA = bodyData();
    BODY_DATA.setBodyData({inited:false})
    if(!USER_DATA.id){
        return
    }
    const res:any = await getUserHealth({userId:USER_DATA.id})
    const inited = Object.keys(res.data).length>0;
    BODY_DATA.setBodyData({inited})
}

export const checkBodyData =()=>{
    const BODY_DATA = bodyData();
    if(!BODY_DATA.inited){
        uni.navigateTo({
            url: `/pages/bodyInfo/bodyInfo`,
        });
    }

    return BODY_DATA.inited
}

export const setBodyData =(obj:any)=>{
    const BODY_DATA = bodyData();
    BODY_DATA.setBodyData(obj);
}